package com.xjrsoft.module.customerTwo.ycode.t_ycode_class.service.impl;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xjrsoft.core.tool.utils.StringUtil;
import com.xjrsoft.module.customerTwo.ycode.t_ycode_class.entity.TYcodeClass;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.xjrsoft.core.tool.utils.CollectionUtil;
import java.util.ArrayList;
import com.xjrsoft.module.customerTwo.ycode.t_ycode_class.dto.TYcodeClassListDto;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xjrsoft.common.page.ConventPage;
import com.xjrsoft.common.page.PageOutput;
import java.util.List;
import com.xjrsoft.module.customerTwo.ycode.t_ycode_class.mapper.TYcodeClassMapper;
import com.xjrsoft.module.customerTwo.ycode.t_ycode_class.service.ITYcodeClassService;
import com.xjrsoft.core.mp.base.BaseService;
import com.xjrsoft.core.tool.utils.Func;
import com.xjrsoft.module.customerTwo.ycode.t_ycode_class.vo.TYcodeClassTreeVo;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;

/**
 *  服务实现类
 *
 * @author dongxinhang
 * @since 2024-07-17
 */
@Service
@AllArgsConstructor
public class TYcodeClassServiceImpl extends BaseService<TYcodeClassMapper, TYcodeClass> implements ITYcodeClassService {


	@Override
	public IPage<TYcodeClass> getPageList(TYcodeClassListDto pageListDto) {
		Wrapper<TYcodeClass> wrapper = Wrappers.<TYcodeClass>query().lambda()
				.like(!StringUtil.isEmpty(pageListDto.getComplete_code()), TYcodeClass::getCompleteCode, pageListDto.getComplete_code())
				.like(!StringUtil.isEmpty(pageListDto.getParent_code()), TYcodeClass::getParentCode, pageListDto.getParent_code());
		return this.page(ConventPage.getPage(pageListDto), wrapper);
	}

	@Override
	public List<TYcodeClass> getList(TYcodeClassListDto pageListDto) {
		Wrapper<TYcodeClass> wrapper = Wrappers.<TYcodeClass>query().lambda()
				.like(!StringUtil.isEmpty(pageListDto.getComplete_code()), TYcodeClass::getCompleteCode, pageListDto.getComplete_code())
				.eq(!StringUtil.isEmpty(pageListDto.getParent_code()), TYcodeClass::getParentCode, pageListDto.getParent_code());
		return this.list(wrapper);
	}

	@Override
	public String addTYcodeClass(TYcodeClass tYcodeClass) {
		String tYcodeClassId = IdWorker.get32UUID();
		tYcodeClass.setId(tYcodeClassId);
		boolean isSuccess = this.save(tYcodeClass);
		return isSuccess ? tYcodeClassId : null;
	}

	@Override
	public boolean updateTYcodeClass(String id, TYcodeClass tYcodeClass) {
		tYcodeClass.setId(id);
		return this.updateById(tYcodeClass);
	}

	public boolean delete(String ids) {
		List<String> idList = Func.toStrList(ids);
		if (this.removeByIds(idList)) {
			return true;
		}
		return false;
	}

	@Override
	public List<TYcodeClassTreeVo> selectYcodeClassForTree() {
		return this.getBaseMapper().selectYcodeClassForTree();
	}

	@Override
	public List<TYcodeClass> getListByParentCode(String parentCode) {
		Wrapper<TYcodeClass> wrapper = Wrappers.<TYcodeClass>query().lambda()
				.eq(!StringUtil.isEmpty(parentCode), TYcodeClass::getParentCode, parentCode);
		return this.list(wrapper);
	}

	@Override
	public List<TYcodeClass> getSecondaryClassList() {
		return this.getBaseMapper().getSecondaryClassList();
	}

}